package com.sh.admin.controller;

import org.springframework.stereotype.Controller;
import sh.dto.ResultDto;
import sh.entity.Classroom;
import com.sh.admin.service.ClassroomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 教室表(Classroom)表控制层
 *
 * @author makejava
 * @since 2021-05-10 14:49:57
 */
@Controller
@RequestMapping("classroom")
public class ClassroomController {
    /**
     * 服务对象
     */
    @Resource
    private ClassroomService classroomService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Classroom selectOne(Integer id) {
        return this.classroomService.queryById(id);
    }

    /**
     * 带条件的查找教室
     * @param classroom
     * @return
     */
    @PostMapping("all")
    public ResultDto findAll(@RequestBody Classroom classroom){
        System.out.println(classroom);
        return classroomService.findAll(classroom);
    }

    /**
     * 查找未使用的教室
     * @return
     */
    @ResponseBody
    @PostMapping("notUse")
    public ResultDto findNotUse(){
        return classroomService.findNotUse();
    }

    /**
     * 添加教室
     * @param classroom
     * @return
     */
    @ResponseBody
    @PostMapping("add")
    public ResultDto insert(@RequestBody Classroom classroom){
        return classroomService.insert(classroom);
    }

    /**
     * 修改教室信息
     * @param classroom
     * @return
     */
    @ResponseBody
    @PostMapping("update")
    public ResultDto update(@RequestBody Classroom classroom){
        return classroomService.update(classroom);
    }

    /**
     * 删除教室
     * @param classroom
     * @return
     */
    @ResponseBody
    @PostMapping("del")
    public ResultDto del(@RequestBody Classroom classroom){
        return classroomService.deleteById(classroom);
    }

}
